package com.kly.user.controller.mybatis;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.kly.user.db.dao.CusomExtDao;
import com.kly.user.mybatis.dynamic.MapperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(value = "/mybatis")
public class MybatisSqlExecutorController {
    @Resource
    private MapperService mapperService;
    @NacosValue(value = "${spring.datasource.druid.url}", autoRefreshed = true)
    private String url;
    @NacosValue(value = "${spring.datasource.druid.username}", autoRefreshed = true)
    private String username;
    @NacosValue(value = "${spring.datasource.druid.password}", autoRefreshed = true)
    private String password;
    @Resource
    CusomExtDao cusomExtDao;

    /**
     * 执行sql, 支持mybatis mapper.xml语法
     */
    @PostMapping(value = "/test")
    public Object test(@RequestBody MybatisParams params) {
        String driver = "com.mysql.cj.jdbc.Driver";
//        String url = "jdbc:mysql://rm-bp1a6261elp30i515fo.mysql.rds.aliyuncs.com:3306/sc-user?characterEncoding=utf8&useSSL=false";
//        String username = "dbadmin";
//        String password = "Li64Edf8*";
        return cusomExtDao.customQuery(params.getSql(), null);

//        return mapperService.execute(params.getSql(), params.getParam(), driver, url, username, password);
    }

}